﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Web.Services;
using System.Collections;
using Catering.View_Operaction;
using Catering_DBOpertion;

namespace Catering.Catering_Page.yl.Daily
{
    public partial class EPromotion : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Rep_Plan.DataSource = null;
                Rep_Plan.DataBind();
                LoadDrop();
                //LoadForm();
            }
        }
        protected void LoadDrop()
        {
            if (Session["User"] != null)
            {
                string userid = Session["PersonnelID"].ToString();
                int companyid = 0;
                int groupid = 0;
                int classid = 0;
                bool isAdmin = false;
                Bind_Data_to_Controls.GetCompanyByCurrentUser(userid, out companyid, out groupid, out classid, out isAdmin);
                Bind_Data_to_Controls.Bind_Area_ddl(ddl_group, isAdmin, groupid, companyid, true, false);
                Bind_Data_to_Controls.Bind_Class_ddl(ddl_group.SelectedItem, ddl_Class, isAdmin, classid, true);
            }
        }
        protected void ddl_group_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddl_group.SelectedItem != null)
            {
                Bind_Data_to_Controls.Bind_Class_ddl(ddl_group.SelectedItem, ddl_Class);
            }
        }

        protected void Drop_BanZu_SelectedIndexChanged(object sender, EventArgs e)
        {
            //DataTable dt_BanZu = new Catering_Rules.ClassInfo().GetList("AreaID=" + this.Drop_ZuoYeQu.SelectedValue).Tables[0];
            //this.DropBind(this.Drop_BanZu, dt_BanZu, "id", "CName");            
        }
        //公用的DropDownList绑定方法
        public void DropBind(DropDownList drop, DataTable dt, string strValue, string strText)
        {
            drop.Items.Clear();
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ListItem item = new ListItem();
                    item.Text = dt.Rows[i][strText].ToString();
                    item.Value = dt.Rows[i][strValue].ToString();
                    drop.Items.Add(item);
                }
            }
        }
        public DataSet SelTJRByDateAndClassID(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 RID");
            strSql.Append(" FROM DailyManagement ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        public DataSet SelPNameByRID(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 Name");
            strSql.Append(" FROM Personnel ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where id = " + int.Parse(strWhere));
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        public void LoadForm()
        {
            Rep_Plan.DataSource = null;
            try
            {
                //DataSet ds = new Catering_Rules.PeiXunQingKuang().GetList(" ribaobianhao like '%," + ddl_Class.SelectedValue + ",%' and fashengshijian between '" + Convert.ToDateTime(txt_stTime.Text).ToShortDateString() + "' and '" + Convert.ToDateTime(txt_endTime.Text).ToShortDateString() + "'");
                //DataTable dt_Plan = ds.Tables[0];
                //dt_Plan.Columns.Add("tempId");
                //dt_Plan.Columns.Add("ClassName");

                //for (int i = 0; i < dt_Plan.Rows.Count; i++)
                //{
                //    dt_Plan.Rows[i]["ClassName"] = ddl_Class.SelectedItem.Text;
                //    dt_Plan.Rows[i]["tempId"] = i + 1;
                //}
                //this.Rep_Plan.DataSource = dt_Plan;
                //this.Rep_Plan.DataBind();
            }
            catch
            {

            }
        }

        protected void Search_Click(object sender, EventArgs e)
        {
            LoadForm();
        }     
    }
}